package net.caidingke.shepherd.domain.customer;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.ebean.annotation.Cache;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.DbDefault;
import io.ebean.annotation.Index;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.caidingke.shepherd.domain.BaseModel;
import net.caidingke.shepherd.domain.customer.finder.CustomerFinder;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * @author bowen
 */
@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@Cache
public class Customer extends BaseModel {

    public static final CustomerFinder F = new CustomerFinder();

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(unique = true)
    private String username;

    @JsonIgnore
    private String password;

    @Index
    private String telephone;

    private String nickname;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DbComment("The date the customer first registered")
    @Temporal(TemporalType.TIMESTAMP)
    private LocalDateTime registered;

    @DbDefault("true")
    private boolean enabled;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Temporal(TemporalType.TIMESTAMP)
    private LocalDateTime lastLoginDate;

    private String lastLoginIp;

    private Long cityId;

}





